dt='2019-02-10'

import_data(){
  sqoop import \
  --connect jdbc:mysql://192.168.56.1:3306/gmall1 \
  --username root \
  --password Admin_111 \
  --driver com.mysql.cj.jdbc.Driver \
  --compress \
  --fields-terminated-by '\t' \
  --lines-terminated-by '\n' \
  --target-dir /hive-data/gmall1/ods/$1/dt=$dt \
  --delete-target-dir \
  --num-mappers 1 \
  --query "$2"' and $CONDITIONS;'

  hive -e "alter table gmall1.$1 add if not exists partition (dt='$dt'); "
}


import_data "ods_sku_info" "select id, spu_id, price, sku_name, sku_desc, weight, tm_id, category3_id, create_time from sku_info where 1=1"
import_data "ods_user_info" "select id, name, birthday, gender, email, user_level, create_time from user_info where 1=1"
import_data "ods_base_category1" "select id, name from base_category1 where 1=1"
import_data "ods_base_category2" "select id, name, category1_id from base_category2 where 1=1"
import_data "ods_base_category3" "select id, name, category2_id from base_category3 where 1=1"

#增量
import_data "ods_order_detail" "select
    od.id,
    order_id,
    user_id,
    sku_id,
    sku_name,
    order_price,
    sku_num,
    o.create_time
  from order_info o, order_detail od
  where o.id=od.order_id
  and DATE_FORMAT(create_time,'%Y-%m-%d')='$dt'"


import_data "ods_payment_info" "select
    id,
    out_trade_no,
    order_id,
    user_id,
    alipay_trade_no,
    total_amount,
    subject,
    payment_type,
    payment_time
  from payment_info
  where DATE_FORMAT(payment_time,'%Y-%m-%d')='$dt'"

#增量+全量
import_data "ods_order_info" "select
    id,
    total_amount,
    order_status,
    user_id,
    payment_way,
    out_trade_no,
    create_time,
    operate_time
  from order_info
  where (DATE_FORMAT(create_time,'%Y-%m-%d')='$dt' or DATE_FORMAT(operate_time,'%Y-%m-%d')='$dt')"


alter table gmall1.ods_sku_info add if not exists partition (dt='2019-02-10');
alter table gmall1.ods_user_info add if not exists partition (dt='2019-02-10');
alter table gmall1.ods_base_category1 add if not exists partition (dt='2019-02-10');
alter table gmall1.ods_base_category2 add if not exists partition (dt='2019-02-10');
alter table gmall1.ods_base_category3 add if not exists partition (dt='2019-02-10');
alter table gmall1.ods_order_detail add if not exists partition (dt='2019-02-10');
alter table gmall1.ods_payment_info add if not exists partition (dt='2019-02-10');
alter table gmall1.ods_order_info add if not exists partition (dt='2019-02-10');
